import React from 'react'
import { Input } from 'antd'
import { connect } from 'umi'

type Props = {
  title: string,
  hero: any,
  father: string,
  type: string,
  dispatch: any,
  iptType: string
}

function MyInput({ title, hero, father, type, dispatch, iptType }: Props) {
  const InpOrText = iptType ? Input.TextArea : Input
  const input = <InpOrText value={father ? hero[father][type] : hero[type]} onChange={(ev) => {
    dispatch({ type: "hero/setProps", shipin: father ? true : false, val: ev.target.value, prop: type })
  }} ></InpOrText>
  return (
    <div className='banner_flex mt15'>
      <span>
        {title}
      </span>
      {
        input
      }
    </div>
  )
}

const mapStateToProps = (state: any) => {
  const { hero } = state
  return {
    hero
  }
}

export default connect(mapStateToProps)(MyInput)